class RestaurantsController < ApplicationController
  # GET /restaurants
  # GET /restaurants.json
  def index
    @restaurants = Restaurant.all

    respond_to do |format|
      format.html # index.html.erb
      format.json  { render :json => @restaurants }
    end
  end

  # GET /restaurants/1
  # GET /restaurants/1.json
  def show
    @restaurant = Restaurant.find(params[:id])
    
    respond_to do |format|
      format.html # show.html.erb
      format.json  { render :json => @restaurant }
    end
  end

  # GET /restaurants/new
  # GET /restaurants/new.json
  def new
    @restaurant = Restaurant.new

    respond_to do |format|
      format.html # new.html.erb
      format.json  { render :json => @restaurant }
    end
  end

  # GET /restaurants/1/edit
  def edit
    @restaurant = Restaurant.find(params[:id])
  end

  # POST /restaurants
  # POST /restaurants.json
  def create
    @restaurant = Restaurant.new(params[:restaurant])

    respond_to do |format|
      if @restaurant.save
        format.html { redirect_to(@restaurant, :notice => 'Restaurant was successfully created.') }
        format.json  { render :json => @restaurant, :status => :created, :location => @restaurant }
      else
        format.html { render :action => "new" }
        format.json  { render :json => @restaurant.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /restaurants/1
  # PUT /restaurants/1.json
  def update
    @restaurant = Restaurant.find(params[:id])

    respond_to do |format|
      if @restaurant.update_attributes(params[:restaurant])
        format.html { redirect_to(@restaurant, :notice => 'Restaurant was successfully updated.') }
        format.json  { head :ok }
      else
        format.html { render :action => "edit" }
        format.json  { render :json => @restaurant.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /restaurants/1
  # DELETE /restaurants/1.json
  def destroy
    @restaurant = Restaurant.find(params[:id])
    @restaurant.destroy

    respond_to do |format|
      format.html { redirect_to(restaurants_url) }
      format.json  { head :ok }
    end
  end

  def getRestById

    @restaurants = Restaurant.where(:id => params[:id])
    respond_to do |format|
      format.json  { render :json => @restaurants}
    end
    
  end


  def createRest

    @rest = Restaurant.new
    @rest.name = params[:name]
    @rest.cuisine = params[:cuisine]
    @rest.descr = params[:descr]
    @rest.phone = params[:phone]
    @rest.email = params[:email].gsub("-", ".")
    @rest.score = 0
    @rest.ncomments = 0

    @rest.save 

    #@local = Local.new
    #@local.name = params[:name]
    #@local.descr = params[:descr]
    #@local.addr1 = " "
    #@local.addrs2  = " "
    #@local.phone1  = " "
    #@local.phone2  = " "
    #@local.capacity  = 50
    #@local.restaurant_id = @rest.id
    #@local.status = 1
    #@local.rate = 0
#
    #@local.save
#
#
    #@dish = Dish.new
    #@dish.name = params[:name]
    #@dish.descr = params[:descr]
    #@dish.cost = 10
    #@dish.menu_id = 1
    #@dish.status = 1 
    #@dish.restaurant_id = @rest.id
    #@dish.rate = 0
#
    #@dish.save

    
    
    respond_to do |format|
      format.json  { render :json => @rest}
    end
    
  end

end
